package cn.px.service.lubricationmanage.impl;

import com.github.pagehelper.PageHelper;
import cn.px.common.bean.AbstractPageResultBean;
import cn.px.dao.bean.MyPage;
import cn.px.dao.dto.lubricationmanage.LubricationPlanDTO;
import cn.px.dao.entity.lubricationmanage.LubricationPlan;
import cn.px.dao.mapper.lubricationmanage.LubricationPlanMapper;
import cn.px.service.lubricationmanage.LubricationPlanService;
import org.springframework.stereotype.Service;
import cn.px.service.base.impl.BaseServiceImpl;
import tk.mybatis.mapper.weekend.Weekend;
import tk.mybatis.mapper.weekend.WeekendCriteria;
import lombok.AllArgsConstructor;

import java.util.List;

/**
 * @Description 润滑计划 service 实现类
 * @author 品讯科技
 * @date 2024-08
 * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
 */
@AllArgsConstructor
@Service("lubricationPlanService")
public class LubricationPlanServiceImpl extends BaseServiceImpl<LubricationPlanMapper, LubricationPlan, LubricationPlanDTO> implements LubricationPlanService {

    @Override
    public int batchDelete(List<String> ids) {
        Weekend<LubricationPlan> weekend = new Weekend<>(LubricationPlan.class);
        WeekendCriteria<LubricationPlan, Object> weekendCriteria = weekend.weekendCriteria();
        weekendCriteria.andIn(LubricationPlan::getId, ids);
        mapper.deleteByExample(weekend);
        return 1;
    }

    @Override
    public AbstractPageResultBean<LubricationPlan> selectPageInfo(LubricationPlanDTO record, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        AbstractPageResultBean<LubricationPlan> pageInfo = new MyPage(mapper.selectPageList(record));
        return pageInfo;
    }

    @Override
    public LubricationPlan getModelById(Object id) {
        LubricationPlan model = mapper.selectById(id);
        return model;
    }
}
